package javase.ch02.created.simple;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Desc TODO
 * @Author chenmin
 * @Date 2025/10/30
 */
public class CallableLambdaDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> task1 = new FutureTask<>(()->{
            int sum = 0;
            for (int i = 0; i < 10; i++) {
                sum+=i;
            }
            return Thread.currentThread().getName()+" sum = "+sum;
        });

        FutureTask<String> task2 = new FutureTask<>(()->{
            int sum = 0;
            for (int i = 0; i < 10; i++) {
                sum+=i;
            }
            return Thread.currentThread().getName()+" sum = "+sum;
        });

        new Thread(task1 , "Thread_A").start();
        System.out.println("Task1执行任务的结果 = "+task1.get());

        new Thread(task2 , "Thread_B").start();
        System.out.println("Task2执行任务的结果 = "+task2.get());
    }

}
